package class1.s2022350143027.data;

import class1.s2022350143027.model.GoodsModel;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品信息数据存放，使用集合进行存储数据
 *
 * @author yzy
 * @date 2024-05-02
 */
public class GoodsData {

    /**自定义集合方式
     * 选择ArrayList
     */
    protected List<GoodsModel> goodsDataList = new ArrayList<>();

    /**
     * 返回商品集合
     * @return goodsDataList
     */
    public List<GoodsModel> getGoodsDataList() {
        return goodsDataList;
    }

    /**
     * 返回商品集合元素个数
     * @return goodsDataList
     */
    public String getLength() {
        return ""+goodsDataList.size();
    }


    // Method to save data to YzyGoodData.txt
//    public void SaveDataToTxt() {
//        try (BufferedWriter writer = new BufferedWriter(new FileWriter("YzyGoodData.txt"))) {
//            for (GoodsModel model : goodsDataList) {
//                String line = model.getGoodId() + "," + model.getGoodName() + "," +
//                        model.getGoodPrice() + "," + model.getGoodNumber();
//                writer.write(line);
//                writer.newLine();  // Move to the next line
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }


}
